<!-- 护理项目列表页 -->
<template>
  <div class="baseList">
    <!-- 新增按钮 -->
    <div class="newBox">
      <button class="bt wt-120" @click="handleBulid()">新增护理项目</button>
    </div>
    <div class="tableBoxs">
      <!-- 当数据为空需要占位时，会显示 cellEmptyContent -->
      <t-table
        row-key="rowKey"
        :data="data"
        :columns="COLUMNS"
        :hover="hover"
        vertical-align="middle"
        :loading="dataLoading"
        tabel-content-width="100%"
        table-layout="fixed"
      >
        <!-- 序号处理 -->
        <template #rowIndex="{ rowIndex }">
          {{ rowIndex + 1 }}
        </template>
        <!-- 图片处理 -->
        <template #image="{ row }">
          <div>
            <div class="tdesign-demo-image-viewer__base">
              <t-image-viewer :images="[row.image]">
                <template #trigger="{ open }">
                  <div class="tdesign-demo-image-viewer__ui-image">
                    <img
                      alt="test"
                      :src="row.image"
                      class="tdesign-demo-image-viewer__ui-image--img"
                    />
                    <div
                      class="tdesign-demo-image-viewer__ui-image--hover"
                      @click="open"
                    >
                      <span> <BrowseIcon size="1.4em" /> 预览 </span>
                    </div>
                  </div>
                </template>
              </t-image-viewer>
            </div>
          </div>
        </template>
        <!-- 价格拼接 -->
        <template #price="{ row }">
          {{ isDecimals(row.price) ? row.price : row.price + '.00' }}
        </template>
        <!-- 操作栏 -->
        <template #op="{ row }">
          <div class="operateCon">
            <a
              class="btn-dl"
              :class="row.count > 0 ? 'disabled' : ''"
              @click="handleDelete(row)"
              >删除</a
            >
            <a
              class="font-bt"
              :class="row.count > 0 ? 'disabled' : ''"
              @click="handleEdit(row)"
              >编辑</a
            >
            <a
              class="delete"
              :class="
                row.count > 0 && row.status === 1
                  ? 'disabled btn-dl'
                  : row.status === 1
                  ? 'btn-dl'
                  : 'font-bt'
              "
              @click="handleForbidden(row)"
              >{{ row.status === 1 ? '禁用' : '启用' }}</a
            >
          </div>
        </template>
      </t-table>
      <!-- 分页 -->
      <t-pagination
        v-if="total > 10"
        v-model="pagination.pageNum"
        v-model:pageSize="pagination.pageSize"
        :total="total"
        @change="onPageChange2"
      />
    </div>
  </div>
</template>

<script setup lang="jsx">
import { COLUMNS } from '../constants'

// 添加isDecimals方法，判断当前字段是否包含了小数点
const isDecimals = (val) => {
  if (String(val).indexOf('.') > -1) {
    return true
  }
  return false
}
/* 接收父组件传递过来的属性 */
const props = defineProps({
  hover: {
    type: Boolean,
    default: false
  },
  dataLoading: {
    type: Boolean,
    default: false
  },
  pagination: {
    type: Object,
    default: () => {
      return {
        pageNum: 1,
        pageSize: 10
      }
    }
  },
  data: {
    type: Array,
    default: () => {
      return []
    }
  },
  total: {
    type: Number,
    default: 0
  }
})
/* 定义接收父组件传递过来的方法 */
const emit = defineEmits([
  'onPageChange',
  'handleBulid',
  'handleEdit',
  'handleForbidden',
  'handleDelete'
])
/* 执行传递过来的单击触发翻页事件 */
const onPageChange2 = (val) => {
  emit('onPageChange', val)
}
const handleBulid = () => {
  emit('handleBulid')
}
const handleEdit = (row) => {
  if (!row.count) {
    emit('handleEdit', row)
  }
}
const handleForbidden = (row) => {
  if (!row.count) {
    emit('handleForbidden', row)
  }
}
const handleDelete = (row) => {
  if (!row.count) {
    emit('handleDelete', row)
  }
}
</script>
